/*
 * @Author: wenl 1255391360@qq.com
 * @Date: 2025-05-20 09:37:30
 * @LastEditors: wenl 1255391360@qq.com
 * @LastEditTime: 2025-05-21 09:27:48
 * @FilePath: \electron-egg\electron\controller\win.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
"use strict";

const { dialog } = require("electron");
const { getMainWindow } = require("ee-core/electron");
const fs = require("fs");
const path = require("path");
const store = require("../store/index");
/**
 * effect - demo
 * @class
 */
class WinController {
  /**
   * select Directory
   */
  selectDirectory() {
    const filePaths = dialog.showOpenDialogSync({
      properties: ["openDirectory"],
    });
    if (!filePaths) {
      return null;
    }
    return filePaths[0];
  }

  /**
   * login window
   */
  closeWin() {
    const win = getMainWindow();
    win.close();
  }
  createFileTest(args) {
    const { path: filePath, content, basePath } = args;
    return new Promise((resolve, reject) => {
      fs.writeFile(path.resolve(basePath + "/" + filePath), content, (err) => {
        if (err) reject(err);
        else resolve(basePath + "/" + filePath);
      });
    });
  }
  setGamePath(args) {
    // const store = new Store();

    const { name, path } = args;
    store.set(name, path);
  }
   getGamePath(args) {
    const { name } = args;
    return store.get(name);
  }
  /**
   * restore window
   */
  restoreWindow(args) {
    const { width, height } = args;
    const win = getMainWindow();

    const size = {
      width: width || 980,
      height: height || 650,
    };
    win.setSize(size.width, size.height);
    win.setResizable(true);
    win.center();
    win.show();
    win.focus();
  }
}
WinController.toString = () => "[class WinController]";

module.exports = WinController;
